<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class ustad_model extends CI_Model {

	function __construct()
	{
		parent::__construct();
		$this->CI = get_instance();
	}
	
	function insert($data) {
        $this->db->insert('ustad', $data);
    }

    function get_ustad() {
        $this->db->select("*");
        $this->db->from('ustad');
        $query = $this->db->get();
        return $query;
    }

    //list flexy
    function get_data_ustad() {
        //Select table name
        $table_name = "ustad";

        //Build contents query
        $this->db->select('*')->from($table_name);
        $this->CI->flexigrid->build_query();

        //Get contents
        $return['records'] = $this->db->get();

        //Build count query
        $this->db->select('*')->from($table_name);
        $this->CI->flexigrid->build_query(FALSE);

        $return['record_count'] = $this->db->count_all_results();

        //Return all
        return $return;
    }

    function delete($id) {
        $this->db->where('ID_ustad', $id);
        $this->db->delete('ustad');
    }

    function selectone($id) {
        $this->db->select("*");
        $this->db->from('ustad');
        $this->db->where('ID_ustad', $id);
        $query = $this->db->get();
        return $query;
    }

    function update($id, $data) {
        $this->db->where('ID_ustad', $id);
        $this->db->update('ustad', $data);
    }
	
	//list flexy
	function get_data_kelas(){
		//Select table name
		$table_name = "KELAS";
		
		//Build contents query
		$this->db->select('*')->from($table_name);
		$this->CI->flexigrid->build_query();
		
		//Get contents
		$return['records'] = $this->db->get();
		
		//Build count query
		$this->db->select('*')->from($table_name);
                $this->CI->flexigrid->build_query(FALSE);
		
		$return['record_count'] = $this->db->count_all_results();
	
		//Return all
		return $return;
	}
	
	
	function getAllGrid($start,$limit,$sidx,$sord,$where){
		$this->db->select('ID_PESERTA','NAMA_PESERTA');
		$this->db->limit($limit);
		if($where != NULL)$this->db->where($where,NULL,FALSE);
		$this->db->order_by($sidx,$sord);
		$query = $this->db->get('peserta',$limit,$start);

		return $query->result();
	}
	
	function get_data_all_ustad(){
		$this->db->select("*");
		$this->db->from('ustad');
		$query = $this->db->get();
		return $query;
	}
	
	
	function cek_ustad_dikelas($id_ustad)
	{	
		$this->db->select('*');
		$this->db->from('kelas');
		$this->db->where('id_ustad', $id_ustad);			
		$query = $this->db->get();
		if ($query->num_rows())
		{
			return FALSE;
		}
		else
		{
			return TRUE;
		}
	}
        
    
	
}

?>